//
//  YMInputTextView.m
//  二级评论
//
//  Created by Andrew on 2018/1/31.
//  Copyright © 2018年 Andrew. All rights reserved.
//

#import "YMInputTextView.h"
#import "UIView+YMExtension.h"

@interface YMInputTextView () <UITextViewDelegate>

/* 输入框 */
@property (nonatomic, weak) UITextView *inputTV;


@end


@implementation YMInputTextView

#define Margin 10

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = YMGrayColor(238);
        
        UITextView *inputTV = [[UITextView alloc] initWithFrame:CGRectMake(Margin, Margin, self.ym_width - Margin * 2, self.ym_height - Margin * 2)];
        inputTV.layer.cornerRadius = 5;
        inputTV.layer.masksToBounds = YES;
        inputTV.layer.borderColor = YMGrayColor(238).CGColor;
        inputTV.layer.borderWidth = 1;
        inputTV.font = LabelFontRegular(16);
        inputTV.delegate = self;
        [self addSubview:inputTV];
        self.inputTV = inputTV;
        [self.inputTV becomeFirstResponder];
        
    }
    return self;
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    
    if ([text isEqualToString:@"\n"]) {
        
        [textView resignFirstResponder];
        
        if (self.InputTextViewReturnBlock) {
            self.InputTextViewReturnBlock(self.indexPath, self.inputTV.text);
        }
        
        return NO;
    }
    
    return YES;
}



@end
